Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
single-line-log
Advanced tools
Keep writing to the same line in the terminal. Very useful when you write progress bars, or a status message during longer operations
The single-line-log npm package allows you to log messages to the console on a single line, overwriting the previous message. This is particularly useful for creating progress bars, status updates, or any other scenario where you want to update the console output without cluttering it with multiple lines.
Basic Single Line Logging
This feature allows you to log messages on a single line, overwriting the previous message. The code sample demonstrates logging 'Loading...', then 'Still loading...' after 1 second, and finally 'Done!' after 2 seconds.
const log = require('single-line-log').stdout;
log('Loading...');
setTimeout(() => log('Still loading...'), 1000);
setTimeout(() => log('Done!'), 2000);
Progress Bar
This feature is useful for creating a progress bar. The code sample shows a progress bar that updates every second, increasing the progress by 10% each time until it reaches 100%.
const log = require('single-line-log').stdout;
let progress = 0;
const interval = setInterval(() => {
progress += 10;
log(`Progress: ${progress}%`);
if (progress >= 100) clearInterval(interval);
}, 1000);
The cli-progress package provides a more advanced and customizable progress bar for command-line interfaces. It offers multiple progress bars, different bar styles, and more control over the appearance and behavior of the progress bars. Compared to single-line-log, cli-progress is more feature-rich and suitable for more complex use cases.
The ora package is a terminal spinner that provides a simple way to display a spinner while performing asynchronous tasks. It supports different spinner styles and colors, and can be used to indicate ongoing operations. While single-line-log focuses on overwriting a single line, ora provides a more visually appealing way to show progress or status updates.
The progress package is another option for creating progress bars in the terminal. It offers a simple API for creating and updating progress bars, with support for custom tokens and formatting. Compared to single-line-log, the progress package is specifically designed for progress bars and offers more customization options.
Node.js module that keeps writing to the same line in the console (or a stream). Very useful when you write progress bars, or a status message during longer operations. Supports multilines.
npm install single-line-log
var log = require('single-line-log').stdout;
// or pass any stream:
// var log = require('single-line-log')(process.stdout);
var read = 0;
var size = fs.statSync('super-large-file').size;
var rs = fs.createReadStream('super-large-file');
rs.on('data', function(data) {
read += data.length;
var percentage = Math.floor(100*read/size);
// Keep writing to the same two lines in the console
log('Writing to super large file\n[' + percentage + '%]', read, 'bytes read');
});
Clears the log (i.e., writes a newline).
var log = require('single-line-log').stdout;
log('Line 1');
log.clear();
log('Line 2');
Outputs to process.stdout
.
Outputs to process.stderr
.
MIT
FAQs
Keep writing to the same line in the terminal. Very useful when you write progress bars, or a status message during longer operations
We found that single-line-log demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.